//
//  FeedBackViewController.m
//  PatientApp
//
//  Created by chirui on 2017/5/18.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "FeedBackViewController.h"
#import "SZTextView.h"

@interface FeedBackViewController ()

@property (nonatomic,strong) SZTextView * sztTextView;

@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor =[UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.titleView = [TopLabel withLabelWithLabelText:@"意见反馈"];
    
    [self creatTextView];
}

- (void)creatTextView {


    self.sztTextView =[[SZTextView alloc]initWithFrame:CGRectMake(0, 10, WIDTH, 150)];
    self.sztTextView.placeholder = @"请输入您想反馈的意见或建议";
    self.sztTextView.font =[UIFont systemFontOfSize:15];
    [self.view addSubview:self.sztTextView];
    
    UIButton * sumBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [sumBtn setTitle:@"提交" forState:UIControlStateNormal];
    sumBtn.frame = CGRectMake((WIDTH-145)/2,200 , 145, 45);
    sumBtn.layer.cornerRadius= 22.5f;
    sumBtn.layer.masksToBounds = YES;
    [sumBtn addTarget:self action:@selector(sumBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [sumBtn setBackgroundImage:ImageName(@"icon_login__buttton_bg")forState:UIControlStateNormal];
    [self.view addSubview:sumBtn];
}

-(void)sumBtnClick {
    
    [self.sztTextView resignFirstResponder];

    if (self.sztTextView.text.length<=0) {
        
        [MBProgressHUD showMessag:@"请填写反馈意见" withDelay:0 toView:self.view withMode:MBProgressHUDModeText hideWithDelay:1.5];
        return;
    }else {
    
        [self requestMessageForNet];
    }
}

-(void)requestMessageForNet{


    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"mid"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"content":self.sztTextView.text,
                           @"type":@"shop"
                           };
    SHuiMBhubNoTimeStr(@"正在提交...");
    [PostNetWorking postNetWorkingStr:RequestUrlStr(feedBook_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
            SHuiMBhudTextTimeStr(@"提交成功！");
            
         dispatch_async(dispatch_get_global_queue(0, 0), ^{
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW , (1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
  
                    [self.navigationController popViewControllerAnimated:YES];
            });
        });
        
        }else {
        
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
         SHuiMBHidleYes;
        SHuiMBhudTextTimeStr(@"网络错误，请检查网络");
        
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
